#![allow(unused_imports)]
#![allow(unused_import_braces)]
#![allow(unused_variables)]
#![allow(non_snake_case)]

pub static mut LOG_FILE: Option<File> = None;
pub mod vulkan;
pub mod system;

use std::{cell::RefCell, fs::File, rc::Rc};
use ash::vk;
use system::{scene::object::static_mesh::StaticMeshObject, GlobalContext};
use vulkan::{vk_utils::utils_time::get_formatted_time, VkConfig};

pub fn main() {
    let formatted_time = get_formatted_time("%y-%m-%d_%H_%M_%S");
    let _ = std::fs::create_dir("./vulkan-rt-test/logs");
    unsafe { 
        LOG_FILE = Some(File::create(format!("./vulkan-rt-test/logs/{formatted_time}_log.txt")).unwrap());
    };

    // Pre Config
    let mut vk_config = VkConfig::new();
    vk_config.verbose_log               = false;
    vk_config.use_debug_utils           = true;
    vk_config.message_severity_flags    = vk::DebugUtilsMessageSeverityFlagsEXT::ERROR | vk::DebugUtilsMessageSeverityFlagsEXT::WARNING | vk::DebugUtilsMessageSeverityFlagsEXT::INFO;
    vk_config.message_type_flags        = vk::DebugUtilsMessageTypeFlagsEXT::GENERAL | vk::DebugUtilsMessageTypeFlagsEXT::VALIDATION | vk::DebugUtilsMessageTypeFlagsEXT::PERFORMANCE;

    vk_config.gen_more_info();

    // Init Global System
    VK_LOGI!("START INIT GlobalContext");
    let mut global_context = GlobalContext::new(&mut vk_config);
    VK_LOGI!("END   INIT GlobalContext");

    let len = 15;
    let half_len = len as f32 / 2.0 ;

    for i in 0..len  {
        for j in 0..len  {
            for k in 0..len  {
                let object = Rc::new(RefCell::new(StaticMeshObject::new(i * 10000 + j * 100 + k, &mut global_context.g_render_system)));
                object.borrow_mut().object_base.location = cgmath::vec3(i as f32 - half_len, j as f32 - half_len, k as f32 - half_len);
                global_context.g_scene_system.add_object(&mut global_context.g_render_system, object);
            }
        }
    }

    global_context.run();
}